import Vue from 'vue'

import '@/mock'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

import i18n from '@/i18n'

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})

Vue.directive('imgerr', {
  inserted(el, options) {
    // console.log(el, options)
    el.addEventListener('error', () => {
      el.src = options.value
    })
    el.src = el.src || options.value
  },
  componentUpdated(el, options) {
    el.src = el.src || options.value
  }
})

import Mycomponent from '@/components'
Vue.use(Mycomponent)

import * as Myfilters from '@/filters'
console.log(Myfilters)
for (const key in Myfilters) {
  Vue.filter(key, Myfilters[key])
}

// 注册全局方法
import myMixin from '@/mixin'
Vue.mixin(myMixin)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
